<template>
  <div class="components-container">
    <div class="header-form">
      <div class="layui-inline" v-if="!IsSendCarUseDateTimenb">
        <label class="layui-form-label">接尸日期</label>
        <div class="layui-input-inline">
          <el-radio-group v-model="seachdataExtent.Bussdate" @change="getData">
            <el-radio-button :label="DateSelectMode.now" class="radio">当日</el-radio-button>
            <el-radio-button :label="DateSelectMode.future" class="radio">以后</el-radio-button>
            <el-radio-button :label="DateSelectMode.all" class="radio">全部</el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div class="layui-inline" v-if="IsSendCarCdhStatus">
        <label class="layui-form-label">派车状态</label>
        <div class="layui-input-inline">
          <el-radio-group v-model="CDHSTATUS" @change="getData">
            <el-radio-button label="" class="radio">全部</el-radio-button>
            <el-radio-button :label="DateSelectMode.now" class="radio">已派车</el-radio-button>
            <el-radio-button :label="DateSelectMode.future" class="radio">未派车</el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div class="layui-inline" v-if="IsSendCarUseDateTime">
          <label class="layui-form-label">火化日期从</label>
          <div class="layui-input-inline">
            <el-date-picker v-date v-model="seachdatatime.RegcremationdateGreaterAndEquals" type="date" placeholder="请选择日期" style="width:160px;" @change="btnSearch"/> 到
            <el-date-picker v-date v-model="seachdatatime.RegcremationdateLessAndEquals" type="date" placeholder="请选择日期" style="width:160px;" @change="btnSearch"/>
          </div>
      </div>
      <div class="layui-inline" v-if="IsSendCarUseDateTimenb">
          <label class="layui-form-label">接尸日期</label>
          <div class="layui-input-inline">
            <el-date-picker v-date v-model="seachdatatime.CdhactualdateGreaterAndEquals" type="date" placeholder="请选择日期" style="width:160px;" @change="btnSearch"/> 到
            <el-date-picker v-date v-model="seachdatatime.CdhactualdateLessAndEquals" type="date" placeholder="请选择日期" style="width:160px;" @change="btnSearch"/>
          </div>
      </div>
      <div class="layui-inline" >
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-inline">
              <el-input  v-model="seachdata.RegnameLike" placeholder="请输入逝者姓名" @keydown.enter.native="btnSearch"></el-input>
            </div>
      </div>
      <div class="layui-inline" >
            <label class="layui-form-label">业务编号</label>
            <div class="layui-inline">
              <el-input  v-model="seachdata.RegbussnumLike" placeholder="请输入业务编号" @keydown.enter.native="btnSearch"></el-input>
            </div>
      </div>
        <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
        <el-button type="warning"  @click="btnRepeat" >重置</el-button>
    </div>
    <!-- 功能列表 -->
    <div>
      <ul class="toolList">
        <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="item in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
              <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
            </li>
        <!-- <li v-if="btnShow('派车')">
          <el-button type="primary" @click="operate('派车')">派车</el-button>
        </li> -->
      </ul>
    </div>
    <!-- 数据列表 -->
    <dataTable :headList="headList" :dataList="dataList" :infos="infos" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <main-model ref="dialog" @refresh="getData"></main-model>
    <carSendNewMain ref="carSendNewMain" @refresh="getData"></carSendNewMain>
    <printmodal ref="printPdf"></printmodal>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>

<script>
import mainModel from "@/views/server/carSendMain";
import carSendNewMain from "./carSendNewMain";
import apiBase from "@/api/apiBase.js";
import dataTable from "@/components/Table/DataTable";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { DATESELECTMODE } from "@/const/const.js";
import printmodal from "@/components/Pdf/Print";
import { ORDER } from "@/const/orderConst.js";
const CARSEND = "派车";
const INFO = "详情";
export default {
  name: "carSendManage",
  mixins: [manage],
  data() {
    return {
      DateSelectMode: DATESELECTMODE,
      //查询条件
      seachdata: {
        RegnameLike: null, // -- 逝者名称
        RegbussnumLike: null,//业务编号
      },
      seachdatatime: {
        RegcremationdateGreaterAndEquals: null, // --开始时间
        RegcremationdateLessAndEquals: null, // -- 结束时间
        CdhactualdateGreaterAndEquals: null, // --宁波开始时间
        CdhactualdateLessAndEquals : null, // -- 宁波结束时间
      },
      seachdataExtent: {
        Bussdate: null
      },
      infos: '义乌详情',
      ischangered: null,
      ischangnb: null,
      IsSendCarUseDateTime: null,
      IsSendCarUseDateTimenb: null,
      IsSendCarCdhStatus: null,
      CDHSTATUS: null,
      isshowxq:null,
    };
  },
  methods: {
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case CARSEND:
          this.$refs.dialog.open(this.order, this.currentRow.BUSSNO, this.currentRow.REGDATE,this.currentRow.REGADDRESS);
          break;
        case '义乌派车':
          this.$refs.carSendNewMain.open(this.order, this.currentRow.BUSSNO,this.currentRow);
          break;
        case '义乌详情':
          this.$refs.carSendNewMain.open(this.order, this.currentRow.BUSSNO);
          break;
        case INFO:
          this.$refs.dialog.open(this.order, this.currentRow.BUSSNO);
          break;
        case '打印派车单':
          this.$refs.printPdf.open(
              this.order,
              this.currentRow.REGPRPID,
              null
          );        
        default:
      }
    },
    //获取表头
    getSendCarColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetAllStaffColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    //获取派车信息
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: JSON.parse(JSON.stringify(this.seachdata))
      };
      let datas = JSON.parse(JSON.stringify(this.seachdata));
      if(this.IsSendCarUseDateTime == true){
        data.Data.RegcremationdateGreaterAndEquals = formatDate(this.seachdatatime.RegcremationdateGreaterAndEquals, "yyyyMMdd");
        data.Data.RegcremationdateLessAndEquals = formatDate(this.seachdatatime.RegcremationdateLessAndEquals, "yyyyMMdd");
      }; 
      if(this.IsSendCarUseDateTimenb == true){
        data.Data.CdhactualdateGreaterAndEquals = formatDate(this.seachdatatime.CdhactualdateGreaterAndEquals, "yyyyMMdd");
        data.Data. CdhactualdateLessAndEquals  = formatDate(this.seachdatatime. CdhactualdateLessAndEquals, "yyyyMMdd");
      }; 
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Sendcar.QuerySendCarRyan,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
          this.dataList.forEach(data => {
            data.REGDATE = data.REGDATE.substring(0, 16);
          });
          this.$nextTick(function() {
              let rows = document.getElementsByClassName("el-table__row");
              if(this.ischangered){
                this.dataList.forEach((item,index) => {
                    rows[index].style.color = '#606266';
                    if(item.REGCRETYPE === 'A'){
                        rows[index].style.color = 'red';
                    }
                });
              };
              if(this.ischangnb){
                this.dataList.forEach((item,index) => {
                    rows[index].style.color = '#606266';
                    if(item.REGCRETYPE === 'A'||item.REGCRETYPE === 'C'){
                        rows[index].style.color ='#007eff';
                    }
                    if(item.REGCRETYPE === 'D'){
                        rows[index].style.color ='red';
                    }
                });
              };
          });
        }
      );
    },
     btnRepeat() {
      this.seachdataExtent.Bussdate = DATESELECTMODE.all;
      this.seachdata.RegdateGreater = null;
      this.seachdata.RegdateEquals = null;
    
      this.CDHSTATUS = DATESELECTMODE.future;

      this.seachdata.RegnameLike = null;
      this.seachdata.RegbussnumLike = null;
      this.seachdatatime.RegcremationdateGreaterAndEquals = new Date();
      this.seachdatatime.RegcremationdateLessAndEquals = new Date();
      this.seachdatatime.CdhactualdateGreaterAndEquals = new Date();
      this.seachdatatime.CdhactualdateLessAndEquals  = new Date();
      this.getData();
    },
    GetIdvDetail() {
            let data = {};
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Param.GetIdvDetail,
                res => {
                    this.issendcar = res.data.content; //是否显示保存按钮
                    if (this.issendcar === '10') {
                        this.infos = "详情";
                    }else if(this.issendcar === '20') {
                        this.infos = "义乌详情";
                    }
                }
            );
        },
    btnShow(btn){
        switch (btn) {
            case '新增':
              return true;
              break;
            case '派车':
              if(this.currentRow) return true;
              break;
            case '详情':
              return true;
              break;
            case '义乌派车':
              if(this.currentRow) return true;
              break;
            case '义乌详情':
              if(this.currentRow) return true;
              break;
            case '打印派车单':
              if(this.currentRow) return true;
              break;
            default: return false;
          }
      },
  },
  components: {
    mainModel,
    dataTable,
    carSendNewMain,
    printmodal
  },
  activated() {
    this.getData();
  },
  created() {
    this.seachdatatime.RegcremationdateGreaterAndEquals = new Date();
    this.seachdatatime.RegcremationdateLessAndEquals = new Date();
    this.seachdatatime.CdhactualdateGreaterAndEquals = new Date();
    this.seachdatatime.CdhactualdateLessAndEquals  = new Date();

    apiBase.DoService({},apiBase.getApiAdress().Param.GetIsDataTableReddening,res => {  //个性化显示高档炉数据变红（义乌true）
        this.ischangered = res.data.content;
    });
    apiBase.DoService({},apiBase.getApiAdress().Param.GetIsCreChangeRed,res => {  //个性化显示高档炉数据变红（宁波true）
        this.ischangnb = res.data.content;
    });
    apiBase.DoService({},apiBase.getApiAdress().Param.GetIsSendCarUseDateTime,res => {
        this.IsSendCarUseDateTime = res.data.content; 
        this.getData();
    });
    apiBase.DoService({},apiBase.getApiAdress().Param.GetCdhactualdateSendCarQuery,res => {
        this.IsSendCarUseDateTimenb = res.data.content; 
        this.getData();
    });
    apiBase.DoService({},apiBase.getApiAdress().Param.GetIsSendCarCdhStatus,res => {
        this.IsSendCarCdhStatus = res.data.content; 
    });
    this.seachdataExtent.Bussdate = DATESELECTMODE.all;
    this.CDHSTATUS = DATESELECTMODE.future;
    //获取表头
    this.getSendCarColumns();
    this.GetIdvDetail();
  },
  watch: {
    "seachdataExtent.Bussdate": function(val) {
      this.seachdata.RegdateGreater = null;
      this.seachdata.RegdateEquals = null;
      switch (val) {
        case DATESELECTMODE.now:
          this.seachdata.RegdateEquals = formatDate(new Date(), "yyyyMMdd");
          break;
        case DATESELECTMODE.future:
          this.seachdata.RegdateGreater = formatDate(new Date(), "yyyyMMdd");
          break;
        default:
          break;
      }
    },
    "CDHSTATUS": function(val){
      switch (val) {
        case DATESELECTMODE.now:
          this.seachdata.CDHSTATUS = "B";
          break;
        case DATESELECTMODE.future:
          this.seachdata.CDHSTATUS = "A";
          break;
        default:
          this.seachdata.CDHSTATUS = null;
          break;
      }
    }
  }
};
</script>